package com.hns.can.safety.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.safety.service.HomeSafeService;
import com.hns.can.safety.vo.UnsafeBhvTimeSummery;

/**
 * 安全首页controller
 * @author:zhangyu
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/homeSafe")
public class HomeSafeController extends BaseController{
	
	@Autowired
	private HomeSafeService homeSafeService;
	//车辆安全指标
	//	车辆故障趋势详细信息 
	//故障车辆排名 
	//故障类型排名
	//	不安全行为趋势详
	//	不安全行为排名
	//	不安全司机排名
	//加载线路站点 用于绘线,描点
	//不安全行为地图
	//获取线路所在城市
	/**
	 * 除指标外，各子功能接口
	 * @param funcType 子功能映射名称
	 * @param dateType 日期类型
	 * @param lineId 线路id
	 * @param drvSctBhvType 不安全行为类型
	 * @param className 转换类型字符串
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping({"/getSafeIndex","/getHarmfulTendency", "/getVehicleFaultsRanking", "/getHarmfulTypeRanking",
		"/unsafeBhvTendency", "/unsafeBhvRanking", "/getUnsafeDriverRanking", "/getLoadLineStnRelDate", 
		"/getUnsafeMap", "/getLoadLineCity"})
	@ResponseBody
	public Object callMethod(String funcType, String dateType, String lineId, String drvSctBhvType, String className, String idxType) throws Exception{
		Map<String, Object> map = formatParams(dateType, lineId, drvSctBhvType, idxType);
		List<T> list = homeSafeService.callMethod(funcType, map, className);
		return this.getReturnResult(list);
	}
	
	/**
	 * 初始化参数
	 * @param dateType 日期类型
	 * @param lineId 线路id
	 * @param drvSctBhvType 不安全行为类型
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	private Map<String, Object> formatParams(String dateType, String lineId, String drvSctBhvType, String idxType){
		SysUserEntity user = this.getCurrentUser().getUser();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dateType", dateType);
		map.put("lineId", lineId);
		map.put("corpId", user.getCorpId());
		map.put("drvSctBhvType", drvSctBhvType);
		map.put("idxType", idxType);
		map.put("userId", user.getId());
		return map;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/getUnsafeTimeData")
	@ResponseBody
	public Object getUnsafeTimeData(String dateType, String lineId, String drvSctBhvType) throws Exception{
		HashMap map = new HashMap();
		map.put("lineId", lineId);
		map.put("dateType", dateType);
		map.put("drvSctBhvType", drvSctBhvType);
		ArrayList<UnsafeBhvTimeSummery> unsafeTimeData = homeSafeService.getUnsafeTimeData(map);
		return this.getReturnResult(unsafeTimeData);
	}
	
}
